package 设计模式.单例模式;

import java.lang.reflect.Field;

/**
 * @author : K k
 * @date : 9:39 2020/8/26
 * 枚举方式
 */
public enum Singleton{
    INSTANCE;

    public void action(){
        System.out.println("执行方法");
    }

    public static void main(String[] args) {
        Singleton.INSTANCE.action();
        try {
            Field instance = Singleton.class.getDeclaredField("INSTANCE");
            System.out.println(instance.equals(Singleton.INSTANCE));

        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }
    }
}
